package com.calm.editor.entity;

import java.util.List;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.google.gson.annotations.Expose;

@Entity
@DiscriminatorValue("XHTML_NODE_ELEMENT")
public class NodeElement extends Element{
	@ManyToOne
	@JoinColumn(name = "PARENT_ID")
	@Expose(serialize = false)
	private NodeElement parent;
	@ManyToOne
	@JoinColumn(name = "PAGE_ID")
	@Expose(serialize = false)
	private Page page;
	
	@OneToMany
	@JoinColumn(name="PARENT_ID")
//	@Expose(serialize = false)
	private List<NodeElement> children;
	
	public NodeElement getParent() {
		return parent;
	}

	public void setParent(NodeElement parent) {
		this.parent = parent;
	}

	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}

	public List<NodeElement> getChildren() {
		return children;
	}

	public void setChildren(List<NodeElement> children) {
		this.children = children;
	}
	public Integer getPageId(){
		if(page!=null){
			return page.getId();
		}
		return null;
	}
	
	public Integer getParentId(){
		if(parent!=null){
			return parent.getId();
		}
		return null;
	}
}
